/**
 * 
 */
package com.sx.article.biz.impl;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.alibaba.fastjson.JSONArray;
import com.sx.article.biz.ITitleInfoBiz;
import com.sx.article.dao.ITitleInfoDao;
import com.sx.article.entity.TitleEntity;
import com.sx.feesunit.exception.SXException;

/**
 * @author Administrator
 *
 */
public class TitleInfoBiz implements ITitleInfoBiz {
	private ITitleInfoDao titleinfodao;
	private Log log = LogFactory.getLog(this.getClass());
	
	/* (non-Javadoc)
	 * @see com.sx.article.biz.ITitleInfoBiz#deleteTitleByArticleId(java.lang.Integer)
	 */
	public boolean deleteTitleByArticleId(Integer aid) throws SXException {
		boolean flag = false;
		try {
			flag = titleinfodao.deleteTitleByArticleId(aid);
		} catch (Exception e) {
			log.error("删除栏目标题与文章关联信息",e);
			throw new SXException(e);
			// TODO: handle exception
		}
		return flag;
	}

	/* (non-Javadoc)
	 * @see com.sx.article.biz.ITitleInfoBiz#findTitleEntityJSONInfo(com.sx.article.entity.TitleEntity)
	 */
	public String findTitleEntityJSONInfo(TitleEntity title) throws SXException {
		String str = "{totalCount:0,data:[]}";
		try {
			List<TitleEntity> list = this.findTitleEntityInfo(title);
			String data = JSONArray.toJSONString(list);
			String count = this.findTitleEntityInfoCount(title);
			str = "{totalCount:"+count+",data:"+data+"}";
		} catch (Exception e) {
			log.error("获取栏目标题JSON信息",e);
			new SXException();
			// TODO: handle exception
		}
		return str;
	}

	/* (non-Javadoc)
	 * @see com.sx.article.biz.ITitleInfoBiz#addTitleInfo(com.sx.article.entity.TitleEntity)
	 */
	public Integer addTitleInfo(TitleEntity title) throws SXException {
		// TODO Auto-generated method stub
		Integer id = null;
		try {
			id = titleinfodao.addTitleInfo(title);
		} catch (Exception e) {
			log.error("新增栏目标题信息",e);
			throw new SXException();
			// TODO: handle exception
		}
		return id;
	}

	/* (non-Javadoc)
	 * @see com.sx.article.biz.ITitleInfoBiz#deleteTitleInfo(com.sx.article.entity.TitleEntity)
	 */
	public boolean deleteTitleInfo(TitleEntity title) throws SXException {
		boolean flag = false;
		try {
			flag = titleinfodao.deleteTitleInfo(title);
		} catch (Exception e) {
			log.error("删除栏目标题信息",e);
			throw new SXException(e);
			// TODO: handle exception
		}
		return flag;
	}

	/* (non-Javadoc)
	 * @see com.sx.article.biz.ITitleInfoBiz#findTitleEntityInfo(com.sx.article.entity.TitleEntity)
	 */
	public List<TitleEntity> findTitleEntityInfo(TitleEntity title)
			throws SXException {
		List <TitleEntity> list = null;
		try {
			list = titleinfodao.findTitleEntityInfo(title);
		} catch (Exception e) {
			log.error("获取栏目标题信息",e);
			// TODO: handle exception
		}
		return list;
	}

	/* (non-Javadoc)
	 * @see com.sx.article.biz.ITitleInfoBiz#findTitleEntityInfoCount(com.sx.article.entity.TitleEntity)
	 */
	public String findTitleEntityInfoCount(TitleEntity title)
			throws SXException {
		String count = null;
		try {
			count = titleinfodao.findTitleEntityInfoCount(title);
		} catch (Exception e) {
			log.error("获取栏目标题数量信息",e);
			// TODO: handle exception
		}
		return count;
	}

	/* (non-Javadoc)
	 * @see com.sx.article.biz.ITitleInfoBiz#updateTitleInfo(com.sx.article.entity.TitleEntity)
	 */
	public boolean updateTitleInfo(TitleEntity title) throws SXException {
		boolean flag = false;
		try {
			flag = titleinfodao.updateTitleInfo(title);
		} catch (Exception e) {
			log.error("更新栏目标题信息",e);
			throw new SXException(e);
			// TODO: handle exception
		}
		return flag;
	}

	/**
	 * @return the titleinfodao
	 */
	public ITitleInfoDao getTitleinfodao() {
		return titleinfodao;
	}

	/**
	 * @param titleinfodao the titleinfodao to set
	 */
	public void setTitleinfodao(ITitleInfoDao titleinfodao) {
		this.titleinfodao = titleinfodao;
	}

}
